<template>
  <j-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="活动细类">
          <j-select-categories-detail placeholder="请选择活动细类"
                                      :multiple="true" v-decorator="['categoriesDetailCode', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="客户">
          <j-select-cust placeholder="请选择客户"
          :multiple="true" v-decorator="['customerCode', {}]" />
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="门店">
          <j-select-terminal placeholder="请选择门店"
                         :multiple="true" v-decorator="['terminalCode', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="申请金额">
          <a-input-number v-decorator="[ 'amount', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="支付方式">
          <cn-dict-select-tag
            placeholder="请选择支付方式"
            dict-code="pay_type"
            triggerChange
            :options="{value:'dictDataCode',label:'dictDataDesc'}"
            v-decorator.trim="[ 'payType', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="预估销售额(客户)">
          <a-input-number v-decorator="[ 'fsalesAmountCustomer', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="预估销售额(门店)">
          <a-input-number v-decorator="[ 'fsalesAmountTerminal', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="备注">
          <a-textarea placeholder="请输入备注" v-decorator="['remarks', {}]" />
        </a-form-item>
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"
  import JSelectCategories from '@/components/cn-select-popup/JSelectCategoriesDetail'
  import JSelectCategoriesDetail from '../../../../components/cn-select-popup/JSelectCategoriesDetail'
  import JSelectCust from '../../../../components/cn-select-popup/CnSelectCust'
  import JSelectTerminal from '../../../../components/cn-select-popup/JSelectTerminal'

  export default {
    name: "TpmActDetailModal",
    props: ['categoriesCode','tempUuid'],
    components: { JSelectTerminal, JSelectCust, JSelectCategoriesDetail,JSelectCategories },
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        status:{rules: [{ required: true, message: '请输入停用启用状态!' }]},
        deleteStatus:{rules: [{ required: true, message: '请输入是否删除!' }]},
        saasid:{rules: [{ required: true, message: '请输入saasid!' }]},
        },
        url: {
          add:window._CONFIG['domianTpmURL']+ "/act/tpmActDetail/saveOrUpdate",
          edit:window._CONFIG['domianTpmURL']+ "/act/tpmActDetail/saveOrUpdate",
        },
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        if (this.tempUuid && typeof this.tempUuid === 'function') {
          const result = this.tempUuid()
          this.model.tempUuid = result;
        }else{
          this.model.tempUuid = this.tempUuid;
        }
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'createName','createDate','createDateTime','updateDate','updateDateTime','updateName','positionCode','positionName','orgCode','orgName','status','deleteStatus','remarks','saasid','actCode','actType','actDetailType','actDetailCode','actSubclassCode','actSubclassName','customerCode','customerName','terminalCode','terminalName','productCode','productName','standPrice','applyPrice','diffPrice','productNum','giftNum','forecastSalesNum','num','amount','payType','currencyTypes','fsalesAmountCustomer','fsalesAmountTerminal','scale','matnr','maktx','price','unit','miniPack','tempUuid','companyCode','priceType','priceGroup','needShare','needStatus','giftCode','giftName','giftStandPrice','auditStatus','auditAmount','categoriesCode','categoriesName','productPolicyCode','productPolicyName','giftCostPrice','giftJson','tempProductNum','tempGiftNum','isStack','productAmount','giftAmount','giftScale','actPriceBuyType','actPriceGiftType','actYearMonth','feeRate','groupCode','tempProductAmount','tempGiftAmount','policyActDetailType','custJson','actPriceDetailDimension','orderAmount','fullreduceType','fullreduceAmount','fullreduceScale','eachFullreduceAmount','isAdd','priceAttribute','discountScale','orgJson信息json','isMultipleAudit','isLimit','productLevelCode','productLevelName','beginDate','endDate','ninTaxPrice','groupAmount','terminalPrice','categoriesDetailCode','categoriesDetailName'))
		  //时间格式化
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
              httpurl+=this.url.add;
              method = 'post';
            let formData = Object.assign(this.model, values);
            //时间格式化

            console.log(formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>